package com.zff.rental.utils.specification;

import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;

import java.util.Collection;

/**
 * 包含任意元素
 *
 * @author HCY
 */
public class LikeAllIn<Root> extends BasePre<Root, String, Collection<String>> {
    public LikeAllIn(String name, Collection<String> value) {
        super(name, value);
    }

    @Override
    protected Predicate generate(CriteriaBuilder cb, Path<String> path, Collection<String>[] params) {
        Collection<String> param = params[0];
        Predicate[] predicates = param.stream()
                .map(s -> cb.like(path, "%" + param + "%"))
                .toArray(Predicate[]::new);
        return cb.or(predicates);
    }
}

